#include "Vector3.hpp"

#include <cmath>
#include <iostream>

namespace Dynamic
{

Vector3::Vector3(double x /*= 0.0*/, double y /*= 0.0*/, double z /*= 0.0*/) : x(x), y(y), z(z)
{

}

double Vector3::Len()
{
	return sqrt(x * x + y * y + z * z);
}

Vector3 Vector3::Norm()
{
	Vector3 tmp = *this;
	double len = this->Len();
	if (len == 0) {
		std::cerr << "Warning! Tried to normalise null vector!" << std::endl;
		return *this;
	}
	tmp.x /= len;
	tmp.y /= len;
	tmp.z /= len;
	return tmp;
}

void Vector3::operator += (const Vector3& b)
{
	if (this != &b) {
		this->x += b.x;
		this->y += b.y;
		this->z += b.z;
	} else {
		this->x *= 2;
		this->y *= 2;
		this->z *= 2;
	}
}

Vector3 Vector3::operator-()
{
	Vector3 tmp = *this;
	tmp.x *= -1.0;
	tmp.y *= -1.0;
	tmp.z *= -1.0;
	return tmp;
}

Vector3 Vector3::operator-(const Vector3& b)
{
	Vector3 tmp = *this;
	tmp.x -= b.x;
	tmp.y -= b.y;
	tmp.z -= b.z;
	return tmp;
}

Vector3 Vector3::operator*(const float& b)
{
	Vector3 tmp = *this;
	tmp.x *= b;
	tmp.y *= b;
	tmp.z *= b;
	return tmp;
}

double Vector3::operator*(const Vector3& b)   // dot product
{
	return x * b.x + y * b.y + z * b.z;
}

Vector3 Vector3::operator+(const Vector3& b)
{
	Vector3 tmp = *this;
	tmp.x += b.x;
	tmp.y += b.y;
	tmp.z += b.z;
	return tmp;
}
}